package php.android;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class ClienteParaPHPActivity extends Activity {
    /** Called when the activity is first created. */
  
	// private static String SOAP_ACTION = "urn:StockControllerwsdl#getPrice"; 
    // private static String NAMESPACE = "http://druizgon.16mb.com"; 
    // private static String METHOD_NAME = "getPrice";  
    // private static String URL = "http://druizgon.16mb.com/servicios/index.php?r=stock/quote&ws=1";
    
	private static String URL = "http://192.168.60.1/servicios2/index.php?r=stock/quote&ws=1";
	private static String NAMESPACE = "http://192.168.60.1";
	private static String SOAP_ACTION = "urn:StockControllerwsdl#getPrice";
	private static String METHOD_NAME = "getPrice";
	
    private EditText editText;
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        
         editText = (EditText) findViewById(R.id.editText1);
        
    }


    public void servicioPHP(final View view) throws SoapFault {
    	
    	  SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);        
          //Use this to add parameters 
         
    	  
    	  request.addProperty("symbol", editText.getText().toString()); 

    	
    	  SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
          envelope.setOutputSoapObject(request); 
          //Needed to make the internet call 
          HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 
          try { 
              //this is the actual part that will call the webservice 
              androidHttpTransport.call(SOAP_ACTION, envelope); 
          } catch (Exception e) { 
              TextView t = (TextView)this.findViewById(R.id.textView1); 
              //Get the first property and change the label text 
              t.setText("FAIL"); 
              e.printStackTrace(); 
          } 
          //SoapObject result = (SoapObject)envelope.bodyIn; 
          SoapPrimitive responses = (SoapPrimitive) envelope.getResponse(); 
          
          if(responses != null){ 
              TextView t = (TextView)this.findViewById(R.id.textView1); 
              //Get the first property and change the label text 
              t.setText(responses.toString()); 
          } 

    	
    }



}